package com.layblog.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;


/**
 * 使用@EnableAsync注解之后就可以使用@Async注解来实现异步了
 *
 * @Author 林必昭
 * @Date 2021/9/6 13:16
 */

@EnableAsync
@Configuration
public class AsyncConfig {

    @Bean
    AsyncTaskExecutor asyncTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setMaxPoolSize(500);   //设置最大线程池的大小
        executor.setCorePoolSize(100);  //设置核心线程池的大小
        executor.setQueueCapacity(25);  //设置队列容量
        return executor;
    }
}
